<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php 
$pr = new Model_DbTable_Pr_Prproducts();
$prMove = new Model_DbTable_Pr_Prstockmovement();
$total = 0;
$i = 1;
?>
<body>
<table  border="1" cellspacing="5" cellpadding="5" style="font-size:15px;">
	<tr>
		<th>No.</th>
		<th>Job Id</th>
		<th>Parts</th>
		<th>Cost</th>	
		<th>Charge</th>
	</tr>
	<?php foreach ($this->rJob as $jobId => $charge){
				$tmppartsList = array();?>
	<?php 
				$tmppartsList = $prMove->getPartsRecordByJobId($jobId);

	?>
  	<tr>
  		<td><?php echo $i++;?></td>
  		<td><?php echo $jobId?></td>
  		<td>
  		<?php if(!empty($tmppartsList)){
  					foreach ($tmppartsList as $key => $value){ ?>
						
						<?php
							$partsD = $pr->getProduct($value['id_product']);
							if($value['code_move'] == 2){
								echo $partsD['code_product']." x ".$value['qty_product']."<br/>";
								
							}else if ($value['code_move'] == 7){
								echo $partsD['code_product']." x -".$value['qty_product']."<br/>";
							}
					}
			  }?></td>
  		<td><?php if(!empty($tmppartsList)){
  					foreach ($tmppartsList as $key => $value){ ?>
						<?php
							$partsD = $pr->getProduct($value['id_product']);
							if($value['code_move'] == 2){
								echo "(".$partsD['price_q']*$value['qty_product'].") + ";
								$total += $partsD['price_q']*$value['qty_product'];
							}else if ($value['code_move'] == 7){
								echo "(-".$partsD['price_q']*$value['qty_product'].") + ";
								$total -= $partsD['price_q']*$value['qty_product'];
							}
					}
			  }?></td>
			  <td><?php echo $charge?>
			  </td>
  	</tr>
  	
  	<?php }?>
  	<tr>
  		<td colspan = "3">Total:</td>
  		<td><?php echo $total?></td>
  	</tr>
</table>
</body>
</html>
